package service

import (
	"context"
	"github.com/bndr/gojenkins"
	"github.com/wonderivan/logger"
	"k8s-platform/config"
	"log"
)

var Jenkins_init jenkins_init

type jenkins_init struct {
	JenkinsClient *gojenkins.Jenkins
}

func (j *jenkins_init) Init() {

	ctx := context.Background()

	jenkinsConfigTest := &config.JenkinsConfigTest{}
	mysqlconfig, err := jenkinsConfigTest.ConfigTest()
	if err != nil {
		log.Fatalf("Failed to parse configuration: %v", err)
	}

	//JENKINS1
	jenkins, err := gojenkins.CreateJenkins(nil, mysqlconfig.Jenkins_url, mysqlconfig.Jenkins_user, mysqlconfig.Jenkins_pass).Init(ctx)
	//JENKINS2
	//jenkins, err := gojenkins.CreateJenkins(nil, "http://47.97.202.142:44496", "admin", "117fa16e4f4f853377f9e85d1b6a363129").Init(ctx)
	if err != nil {
		logger.Error("初始化jenkins失败", err)
	} else {
		logger.Info("初始化jenkins成功")
	}
	//初始化jenkins
	j.JenkinsClient = jenkins
}
